package net.shopxx.dao.impl;

import java.util.List;

import net.shopxx.bean.Pager;
import net.shopxx.bean.Pager.OrderType;
import net.shopxx.dao.IndexflooradvDao;
import net.shopxx.entity.Indexfloor;
import net.shopxx.entity.Indexflooradv;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Repository;

/**
 * Dao实现类 - 首页楼层tab
 */

@Repository
public class IndexflooradvDaoImpl extends BaseDaoImpl<Indexflooradv, String> implements IndexflooradvDao {
	
	@SuppressWarnings("unchecked")
	public List<Indexflooradv> getEnabledIndexflooradvList() {
		String hql = "from Indexflooradv indexflooradv where indexflooradv.isEnabled = ? order by indexflooradv.orderList asc";
		return getSession().createQuery(hql).setParameter(0, true).list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Indexflooradv> getEnabledIndexflooradvList(Indexfloor indexfloor) {
		String hql = "from Indexfloortab indexfloortab where indexfloortab.isEnabled = ? and indexfloortab.indexfloor = ? order by indexfloortab.orderList asc";
		return getSession().createQuery(hql).setParameter(0, true).setParameter(1, indexfloor).list();
	}
	
	
	
	// 根据orderList排序
	@SuppressWarnings("unchecked")
	@Override
	public List<Indexflooradv> getAll() {
		String hql = "from Indexfloortab indexfloortab order by indexfloortab.orderList asc indexfloortab.createDate desc";
		return getSession().createQuery(hql).list();
	}

	// 根据orderList排序
	@Override
	@SuppressWarnings("unchecked")
	public List<Indexflooradv> getList(String propertyName, Object value) {
		String hql = "from Indexflooradv indexflooradv where indexflooradv." + propertyName + "=? order by indexflooradv.orderList asc indexflooradv.createDate desc";
		return getSession().createQuery(hql).setParameter(0, value).list();
	}
	
	// 根据orderList排序
	@Override
	public Pager findByPager(Pager pager, DetachedCriteria detachedCriteria) {
		if (pager == null) {
			pager = new Pager();
			pager.setOrderBy("orderList");
			pager.setOrderType(OrderType.asc);
		}
		return super.findByPager(pager, detachedCriteria);
	}

	// 根据orderList排序
	@Override
	public Pager findByPager(Pager pager) {
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Indexflooradv.class);
		return this.findByPager(pager, detachedCriteria);
	}
	
	// 重写方法，删除的同时清除关联
	@Override
	public void delete(Indexflooradv indexflooradv) {
		super.delete(indexflooradv);
	}

	// 重写方法，删除的同时清除关联
	@Override
	public void delete(String id) {
	    Indexflooradv indexflooradv = load(id);
		this.delete(indexflooradv);
	}

	// 重写方法，删除的同时清除关联
	@Override
	public void delete(String[] ids) {
		for (String id : ids) {
			this.delete(id);
		}
	}

}